﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WS.EKA.Business.Service;
using System.Threading.Tasks;
using System.Diagnostics;


namespace WS.EKA.Business.Test
{
    [TestClass]
    public class ServiceTest
    {
        int m = 0;
        object o = new object();
        public int GetId
        {
            get
            {
                //lock (o)
                //{
                    return ++m;
                //}
            }
        }
        public void EventServiceTest()
        {
            string target = "event";
            string data = "{\"Event_Id\": {0},\"Event_Level\":\"H\",\"Ticket_Id\":\"111\",\"Event_Source\":\"source\",\"Host_Id\":\"deppon\",\"Begin_Time\":\"2013-11-1\",\"Event_Desc\":\"desc\",\"Status\":\"1\",\"App_Name\":\"App_Name\",\"APP_Code\":\"APP_Test\"}";
            //IService service = ServiceFactory.CreateService(target);
            //if (service == null)
            //    Assert.Fail("target error!");
            //else
            //    service.ImportData(data);
            int k = 0;
            for (int i = 1; i <= 2; i++)
            {
                data = "{\"Event_Id\":"+ i.ToString() + ",\"Event_Level\":\"H\",\"Ticket_Id\":\"111\",\"Event_Source\":\"source\",\"Host_Id\":\"deppon\",\"Begin_Time\":\"2013-11-1\",\"Event_Desc\":\"desc\",\"Status\":\"1\",\"App_Name\":\"App_Name\",\"APP_Code\":\"APP_Code\"}";
                SyncData.SyncData.ExecuteByMSMQ(target, data);
            }

        }


        public void EventServiceMultiThreadTest()
        {
            Task[] ts = new Task[1];
            int n = 1;
            for (int i = 0; i < ts.Length; i++)
            {
                ts[i] = Task.Factory.StartNew(() =>
                {
                    for (int k = 0; k < 10; k++)
                    {
                        string args =  "-target event -data {\"Event_Id\": "+n.ToString()+",\"Event_Level\":\"H\",\"Ticket_Id\":\"111\",\"Event_Source\":\"source\",\"Host_Id\":\"deppon\",\"Begin_Time\":\"2013-11-1\",\"Event_Desc\":\"desc\",\"Status\":\"1\",\"App_Name\":\"App_Name\",\"APP_Code\":\"APP_Code\"}";
                        n++;
                        //Console.WriteLine(string.Format("Task:{0}", i));
                        Process p = new Process();
                        p.StartInfo = new ProcessStartInfo("WS.EKA.SyncData.exe",args);
                    }
                    
                });
                //ts[i].Start();
            }

            //Thread t1 = new Thread(new ThreadStart(EventServiceTest));
            //t1.Start();

        }

        public void IncidentServiceTest()
        {
            Deppon.IncidentServiceSoapClient service = new Deppon.IncidentServiceSoapClient();
            //service.Url = "http://192.168.67.137/Service/IncidentService.asmx";
            service.SaveIncident("8", "5", "5", "5", "5", "", "", "Test 5", null, null, null, "", "", "", "", "", "", "", "", "", "", "", "", null,
                null, "Submitter", null, "", null, "", null);
        }


    }
}
